package com.example.framework.manager;

import android.content.Context;
import android.view.Gravity;

import com.example.framework.R;
import com.example.framework.view.DialogView;

/**
 * @author:0.2℃
 * @date： 2022-04-02 17:01
 * @Description ：提示框管理类，保证唯一类
 */
public class DialogManager {
    private static volatile DialogManager dialogInstance = null;

    private DialogManager() {

    }

    public static DialogManager getDialogInstance () {
        if (dialogInstance == null) {
            synchronized(DialogManager.class) {
                if (dialogInstance == null) {
                    dialogInstance = new DialogManager();
                }
            }
        }
        return dialogInstance;
    }

    /**
     * 默认Dialog位置居中
     * @param mContext
     * @param layout
     * @return
     */
    public DialogView initView(Context mContext, int layout) {
        return new DialogView(mContext, layout, R.style.Theme_Dialog, Gravity.CENTER);
    }

    /**
     * 使用一个重载，来定义自己的位置
     * @param mContext
     * @param layout
     * @param gravity
     * @return
     */
    public DialogView initView (Context mContext, int layout, int gravity) {
        return new DialogView(mContext, layout, R.style.Theme_Dialog, gravity);
    }

    public void showDialog(DialogView dialogView) {
        if (dialogView != null){
            if (!dialogView.isShowing()) {
                dialogView.show();
            }
        }
    }

    public void hideDialog(DialogView dialogView) {
        if (dialogView != null) {
            if (dialogView.isShowing()) {
                dialogView.dismiss();
            }
        }
    }
}
